package com.itheima.edu.info.manager.service.impl;

import com.itheima.edu.info.manager.dao.IStudentDao;
import com.itheima.edu.info.manager.dao.impl.StudentDaoImpl;
import com.itheima.edu.info.manager.pojo.Student;
import com.itheima.edu.info.manager.service.IStudentSrevice;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * @author daiweiyuan
 */
public class StudentServiceImpl implements IStudentSrevice {
    private IStudentDao dao = new StudentDaoImpl();

    @Override
    public boolean addStudent(Student stu) {
        return dao.addStudent(stu);
    }

    @Override
    public ArrayList<Student> findAllStudent() {
        return dao.findAllStudent();
    }

    @Override
    public boolean isExist(String id) {
        ArrayList<Student> list = dao.findAllStudent();
        for (Student stu : list) {
            if (stu.getId().equals(id)) {
                //存在
                return true;
            }
        }
        //不存在
        return false;
    }

    @Override
    public int getBirthday(String birthday) throws ParseException {
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = sdf.parse(birthday);
        int year = parse.getYear();
        int year1 = now.getYear();
        return year1-year;
    }


}
